package com.example.checkqufuface.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.example.checkqufuface.R;
import com.example.checkqufuface.bean.QufufindFreeCardProductSelectResultBean;

import java.util.List;

public class FreeTypeAdapter extends BaseAdapter {

    private Context context;
    private List<QufufindFreeCardProductSelectResultBean.DataBean> dataList;
    public GridViewItemListener gridViewItemListener;

    public FreeTypeAdapter(Context context, List<QufufindFreeCardProductSelectResultBean.DataBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View menuItem = LayoutInflater.from(context).inflate(R.layout.widget_free_in_item, null);
        Button freeName = menuItem.findViewById(R.id.bt_wight_free_name);
        freeName.setText(dataList.get(position).getScenicTicketName());

        freeName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gridViewItemListener.gvItem(position);
            }
        });
        return menuItem;
    }

    public interface GridViewItemListener{
        void gvItem(int pos);
    }

    public void SetGridViewItemListener(GridViewItemListener gridViewItemListener){
        this.gridViewItemListener = gridViewItemListener;
    }
}
